-- mop_up
-- Created by chengb Sep/11/2015
-- 成就：扫荡

-- 内部函数声明
local whenMopUp;

-- 注册扫荡的回调
EventMgr.register("game_achievement/mop_up", event.MOP_UP_DONE, function(args)
    whenMopUp(args);
end);

-- 注册扫荡的回调
whenMopUp = function(args)
    -- 判断是否是符合要求的成就
    local function isValidId(id)
        if true == GameAchievementM.isCompleted(id) then
            -- 已经完成了
            return false;
        end
        
        return true;
    end
    
    -- 遍历所有的子规则
    local ids = GameAchievementM.getIdsByRule("mop_up");
    for _, id in pairs(ids) do
        if isValidId(id) then
            -- 尝试完成成就
            GameAchievementM.tryComplete(id, 1);
        end
    end
end

return {
    -- 获取成就描述
    queryDesc = function(id)
        local config = GameAchievementM.query(id);

        local ruleArg  = config["rule_arg"];
        local progress = config["progress"];
        local desc     = config["desc"];
        
        desc = string.gsub(desc, "{0}", progress);

        return desc;
    end,
};